﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Zeus.Thunder.Core;
using CsharpTrainer.Model.Entities;
using System.IO.Compression;

namespace SharpTrainer.FileStreams
{
    class BinaryReaderWriterTest : ITestCase
    {
        public void Run()
        {
            using (FileStream fs = File.Create("binary_test.txt"))
            {
                List<Employee> employees = new List<Employee>
                {
                    new Employee { EmployeeID = 1, LastName = "Gu", FirstName = "David", Title = "Senior Developer", City = "Shanghai", Region = "", Country = "China", Notes = "test" },
                    new Employee { EmployeeID = 2, LastName = "Gu", FirstName = "Kelvin", Title = "Senior Manager", City = "Shanghai", Region = "", Country = "China", Notes = "test2" }
                };

                foreach (Employee employee in employees)
                {
                    employee.SaveData(fs);
                }
            }

            using (FileStream fs = File.OpenRead("binary_test.txt"))
            {
                List<Employee> employees = new List<Employee>();

                Employee employee = new Employee();
                while (employee.LoadData(fs))
                {
                    employee.LoadData(fs);
                    employees.Add(employee);

                    employees.Add(employee);
                    employee = new Employee();
                }

                foreach (Employee emp in employees)
                {
                    Console.WriteLine(emp);
                    Console.WriteLine("--------------------------------------------");
                }
            }
        }
    }
}
